package com.example.qxfw.backgroundManagement.mapper;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.example.qxfw.common.entity.GroupInfo;
import com.example.qxfw.common.entity.Liaison;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author ZeLin Wang
 * @version 1.0
 * @description: 后台管理-通讯录管理
 * @date 2024/7/3 10:13
 */
@Mapper
@DS("service")
public interface AddressManagementMapper {

    @Select("select * from liaison_group")
    List<GroupInfo> selectAllGroup();

    @Select("select * from liaison")
    List<Liaison> selectAllLiaison();

    @Insert("insert into liaison_group(id,groupname) " +
            "values (#{id},#{groupName})")
    Integer addGroupInfo(@Param("id") int id,@Param("groupName") String groupName);

    @Delete("delete from liaison_group where id = #{id}")
    Integer deleteGroupInfo(@Param("id") int id);

    @Insert("insert into liaison(id,name,job,phone,groupname,level,villagename,countryname) " +
            "values (#{id},#{name},#{job},#{phone},#{groupName},#{level},#{villageName},#{countryName})")
    Integer addLiaisonInfo(Liaison liaison);

    @Select("select case when count(*) = 0 then 0 " +
            "else (select id from liaison_group order by id desc limit 1) " +
            "end from liaison_group")
    Integer selectGroupIdMax();

    @Select("select case when count(*) = 0 then 0 " +
            "else (select id from liaison order by id desc limit 1) " +
            "end from liaison")
    Integer selectLiaisonIdMax();

    @Update("update liaison " +
            "set name=#{name},job=#{job},phone=#{phone},groupname=#{groupName},level=#{level},villagename=#{villageName},countryname=#{countryName} " +
            "where id = #{id}")
    Integer updateLiaisonInfo(Liaison liaison);

    @Delete("delete from liaison where id = #{id}")
    Integer delLiaisonInfo(@Param("id") int id);
}
